const express=require('express')
const  mongoose=require("mongoose")




const app=express()



mongoose.connect('mongodb://localhost/playing')
.then(res=>console.log('成功'))
.catch(err=>{console.log('失败')})

const UserSchma=new mongoose.Schema({
    name:String,
    age:Number,
    hobbies:[String]
})

   const Users=mongoose.model('Users',UserSchma)

// 如何查询条件匹配了多个文档 那么将会删除第一个匹配的文档
   Users.findOneAndDelete({_id:'5fa7771b77a8463650b8cd98'}).then(res=>{console.log(res)})


//删除多个
// Users.deleteMany({age:{$lt:990,$gt:9}}).then(res=>{console.log(res)})


//删除所有  

Users.deleteMany({}).then(res=>{console.log(res)})




//更新数据 



//更新1条数据
// Users.updateOne({_id:'5fa7771b77a8463650b8cd96'},{name:'小小',age:100,hobbies:['唱歌','游泳']})
// .then(res=>console.log(res))


//更新多条数据
// Users.updateMany({},{age:500}).then(res=>console.log(res))


// Users.updateMany({age:{$lt:15,$gt:10}},{age:999}).then(res=>console.log(res))



app.listen(3000,()=>{
    console.log('3000启动')
})
